package core.rendering;

import java.awt.AlphaComposite;
import java.awt.Dimension;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.geom.AffineTransform;

public abstract class Renderable {

	public Dimension size;
	float x;
	float y;
	
	float alpha;
	float scale;
	float rotation;

	/**
	 * Default constructor
	 */
	public Renderable() {
		x = 0f;
		y = 0f;
		alpha = 1.0f;
		scale = 1.0f;
		rotation = 0.0f;
	}
	
	

	/**
	 * Position constructor
	 * 
	 * @param x_
	 *            x coordinate.
	 * @param y_
	 *            y coordinate.
	 */
	public Renderable(float x_, float y_) {
		x = x_;
		y = y_;
		alpha = 1.0f;
		scale = 1.0f;
		rotation = 0.0f;
	
	}

	public void prepareGraphics(Graphics2D g2d){
		
		g2d.setComposite((AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha)));		
	}
	
	public void restoreGraphics(Graphics2D g2d){
		g2d.setComposite((AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1)));
	}
	
	
	
	/**
	 * @return the alpha
	 */
	public float getAlpha() {
		return alpha;
	}



	/**
	 * @param alpha the alpha to set
	 */
	public void setAlpha(float alpha) {
		this.alpha = alpha;
	}
	
	/**
	 * Renders this element.
	 * 
	 * @param g2d
	 *            the Graphics2D.
	 */
	public void render(Graphics2D g2d){
		prepareGraphics(g2d);
		renderComponent(g2d);
		restoreGraphics(g2d);
	}
	
	public abstract void renderComponent(Graphics2D g2d);

	public void setPosition(float x_, float y_) {
		x = x_;
		y = y_;
	}

	public float getX() {
		return x;
	}

	public void setX(float x_) {
		x = x_;
	}

	public float getY() {
		return y;
	}

	public void setY(float y_) {
		y = y_;
	}

	public Dimension getSize() {
		return size;
	}

	public void setSize(Dimension size) {
		this.size = size;
	}

	public abstract void updateLogic();

}
